#pragma warning(disable:4786)
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
void Exercise1()
{
	typedef vector<char>::reverse_iterator VRI;
	vector<char> VChar;
	for( char c = 'A';c<='z';c++)
		VChar.push_back(c);
	cout<<"The order in the VChar is:"<<endl;
	for(vector<char>::iterator vi = VChar.begin();vi!=VChar.end();vi++)
		cout<<*vi;
	cout<<endl;
	cout<<"The reverse order is :"<<endl;
	for( VRI vri = VChar.rbegin();vri !=VChar.rend();vri++)
		cout<<*vri;
	cout<<endl;
}
void Exercise2()
{
	vector <string> fruits;
	vector<string>::iterator vi ;
	fruits.push_back("Apple");
	fruits.push_back("Peach");
	fruits.push_back("kiwifuit");
	fruits.push_back("pear");
	fruits.push_back("starfruit");
	fruits.push_back("grape");
	cout<<"Befor the sorting:"<<endl;
	for( vi =fruits.begin();vi != fruits.end();vi++)
		cout<<*vi<<" ";
	cout<<endl;
	cout<<"sort the vector:"<<endl;
	sort(fruits.begin(),fruits.end());
	for(vi =fruits.begin();vi != fruits.end();vi++)
		cout<<*vi<<" ";
	cout<<endl;
}
bool BeginWithP(string str)
{
	return str[0] == 'p';
}
bool BeginWithA(string str)
{
	return str[0] == 'a';
}
void Exercise3_4()
{
	vector <string> fruits;
	vector<string>::iterator vi ;
	fruits.push_back("apple");
	fruits.push_back("Peach");
	fruits.push_back("kiwifuit");
	fruits.push_back("pear");
	fruits.push_back("starfruit");
	fruits.push_back("anull");
	fruits.push_back("grape");
	fruits.push_back("agrape");
	cout<<"Befor the sorting:"<<endl;
	for( vi =fruits.begin();vi != fruits.end();vi++)
		cout<<*vi<<" ";
	cout<<endl;
	cout<<"sort the vector:"<<endl;
	sort(fruits.begin(),fruits.end());
	for(vi =fruits.begin();vi != fruits.end();vi++)
		cout<<*vi<<" ";
	cout<<endl;
	//find the first fruit begin with letter 'p',pay attention to the BeginWithP fuction,
	//it has a string argument
	vi = find_if(fruits.begin(),fruits.end(),BeginWithA);
	vector<string>::reverse_iterator rvi = 
		find_if(fruits.rbegin(),fruits.rend(),BeginWithA);
	cout<<*vi<<endl;
	cout<<*rvi<<endl;
	cout<<*rvi.base()<<endl;
	// notice the the use of base(),,,,
	fruits.erase(vi,rvi.base());
	for(vi =fruits.begin();vi != fruits.end();vi++)
		cout<<*vi<<" ";
	cout<<endl;


}
void main()
{
	Exercise3_4();
}